<template>
  <div class="oneboard">
    <div class="oneboard-one">
      <div>个人仓库质检统计数据</div>
      <div>
        <div>
          <div>本日仓库质检数量（合格/不合格 总数）</div>
          <div>
            <span>{{ datastatistics.today.pass }}</span> /
            <span>{{ datastatistics.today.unpass }}</span>
            <span style="margin-left:20px">{{ datastatistics.today.num }}(总数)</span>
          </div>
          <div>
            仓库质检合格率
            <span>{{ (datastatistics.today.pass_rate * 100).toFixed(2) }}%</span>
          </div>
        </div>
        <div></div>
        <div>
          <div>7日仓库质检数量（合格/不合格 总数）</div>
          <div>
            <span>{{ datastatistics.seven.pass }}</span> /
            <span>{{ datastatistics.seven.unpass }}</span>
            <span style="margin-left:20px">{{ datastatistics.seven.num }}(总数)</span>
          </div>
          <div>
            仓库质检合格率
            <span>{{ (datastatistics.seven.pass_rate * 100).toFixed(2) }}%</span>
          </div>
        </div>
        <div></div>
        <div>
          <div>历史仓库质检数量（合格/不合格 总数）</div>
          <div>
            <span>{{ datastatistics.history.pass }}</span> /
            <span>{{ datastatistics.history.unpass }}</span>
            <span style="margin-left:20px">{{ datastatistics.history.num }}(总数)</span>
          </div>
          <div>
            仓库质检合格率
            <span>{{ (datastatistics.history.pass_rate * 100).toFixed(2) }}%</span>
          </div>
        </div>
      </div>
    </div>

    <div class="oneboard-three">
      <div>个人仓库质检历史数据</div>
      <el-form ref="form" :model="form" label-position="top" class="myform">
        <div>
          <el-form-item label="仓库验货日期:">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="form.qc_time"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="质检结果" style="margin-left: 20px" class="myform-item">
            <el-select v-model="form.status" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
            <el-button
              type="primary"
              @click="onSearch"
              style="margin-left: 20px"
              >查询</el-button
            >
          </el-form-item>
        </div>
        <div></div>
      </el-form>
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column label="仓库质检员" align="center" prop="qc_user">
        </el-table-column>
        <el-table-column label="验货期" align="center" prop="qc_time">
        </el-table-column>
        <el-table-column label="RFID编码" align="center" prop="number">
        </el-table-column>
        <el-table-column label="质检结果" align="center" prop="reason_title">
          <template slot-scope="{ row }">
            {{ row.reason_title || "合格" }}
          </template>
        </el-table-column>
        <el-table-column label="图片" align="center" prop="reason_title">
          <template slot-scope="{ row }" v-if="row.reason_title">
            <el-image :src="row.qc_img" style="width:100px" fit="scale-down" :lazy="true" :preview-src-list="[row.qc_img]"></el-image>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :form="form"
        :total="total"
        @paginationPostOrderTaskList="postApiCodeGetQtdetaillist"
      />
    </div>
  </div>
</template>

<script>
import { postApiCodeGetQtdetail, postApiCodeGetQtdetaillist } from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      datastatistics: "",
      form: {
        user_id: "",
        qc_time: "",
        status:"",
        page: 1,
        size: 10,
      },
       options:[
        {
          label:"不限",
          value:""
        },
        {
          label:"合格",
          value:1
        },
        {
          label:"不合格",
          value:0
        }
      ],
      total: 0,
      tableData: [],
    };
  },
  async created() {
    this.form.user_id = this.$route.query.id;
    let form = this.form;
    this.postApiCodeGetQtdetail();
    this.postApiCodeGetQtdetaillist(form);
  },
  activated() {
    if (this.$route.query.id) {
      this.form.user_id = this.$route.query.id;
      let form = this.form;
      this.postApiCodeGetQtdetail();
      this.postApiCodeGetQtdetaillist(form);
    }
  },
  methods: {
    // 仓库质检--数据统计
    postApiCodeGetQtdetail() {
      let obj = {
        user_id: this.form.user_id,
      };
      postApiCodeGetQtdetail(obj).then((res) => {
        console.log("仓库质检--数据统计", res);
        this.datastatistics = res.data;
      });
    },
    // 仓库质检--数据列表
    postApiCodeGetQtdetaillist(form) {
      this.form = form;
      let data = JSON.parse(JSON.stringify(form));
      if (data.qc_time) {
        data.qc_time = data.qc_time[0] + "/" + data.qc_time[1];
      }
      postApiCodeGetQtdetaillist(data).then((res) => {
        console.log("仓库质检--数据列表", res);
        this.tableData = res.data;
        this.total = Number(res.total) 
      });
    },
    // 查询
    async onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      let form = this.form;
      this.postApiCodeGetQtdetaillist(form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.oneboard {
  > div {
    background: #fff;
    padding: 40px 20px;
    border-radius: 4px;
    margin-bottom: 20px;
  }
  &-one {
    > div:nth-child(1) {
      font-size: 18px;
      font-weight: 800;
      margin-bottom: 20px;
    }
    > div:nth-child(2) {
      display: flex;
      justify-content: space-around;
      align-items: center;
      > div {
        display: flex;
        flex-direction: column;
        > div:nth-child(1) {
          color: #999;
          font-size: 14px;
          padding-bottom: 10px;
        }
        > div:nth-child(2) {
          font-size: 18px;
          font-weight: 600;
          > span:nth-child(1) {
            color: #71d5a1;
          }
          > span:nth-child(2) {
            color: #f55547;
          }
        }
        > div:nth-child(3) {
          font-size: 12px;
          padding-top: 10px;
          > span {
            font-size: 18px;
            color: #409eff;
          }
        }
      }
      > div:nth-child(2n) {
        width: 1px;
        height: 15px;
        background: #f0f1f7;
      }
    }
  }
  &-three {
    > div:nth-child(1) {
      font-size: 18px;
      font-weight: 800;
      margin-bottom: 20px;
    }
  }
}
</style>